<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <label class="layui-form-label required">视频图片</label>
        <div class="layui-input-block">
            <input type="text" name="movie_Name" lay-verify="required" lay-reqtext="视频图片不能为空" placeholder="请存入视频图片" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">视频名称</label>
        <div class="layui-input-block">
            <input type="text" name="movie_Name" lay-verify="required" lay-reqtext="视频名称用户名不能为空" placeholder="请输入视频名称" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">视频译名</label>
        <div class="layui-input-block">
            <input type="text" name="movie_ChineseName" lay-verify="required" lay-reqtext="视频译名不能为空" placeholder="请输入视频译名" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">年代</label>
        <div class="layui-input-block">
            <input type="text" name="movie_Age" lay-verify="required" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">产地</label>
        <div class="layui-input-block">
            <input type="text" name="movie_Place" lay-verify="required" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">类别</label>
        <div class="layui-input-block">
            <input type="text" name="movie_Type" lay-verify="required" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">语言</label>
        <div class="layui-input-block">
            <input type="text" name="movie_Language" lay-verify="required" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">字幕</label>
        <div class="layui-input-block">
            <input type="text" name="movie_Subtitle" lay-verify="required" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">上映时间</label>
        <div class="layui-input-block">
            <input type="text" name="movie_ReleaseDate" id="date1" autocomplete="off" class="layui-input"
                   lay-verify="required" lay-reqtext="上映时间不能为空"/>
        </div>

    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">IMDb评分</label>
        <div class="layui-input-block">
            <input type="text" name="movie_IMDbScore" lay-verify="required" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">豆瓣评分</label>
        <div class="layui-input-block">
            <input type="text" name="movie_DBScore" lay-verify="required" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">片长</label>
        <div class="layui-input-block">
            <input type="text" name="movie_Times" lay-verify="required" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">导演</label>
        <div class="layui-input-block">
            <input type="text" name="movie_Director" lay-verify="required" lay-reqtext="导演不能为空" placeholder="请输入导演名字" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">编剧</label>
        <div class="layui-input-block">
            <input type="text" name="movie_Scriptwriter" lay-verify="required" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">主演</label>
        <div class="layui-input-block">
            <input type="text" name="movie_Actor" lay-verify="required" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">简介</label>
        <div class="layui-input-block">
            <textarea name="remark" class="movie_Introduction" placeholder="请输入视频简介"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">视频链接</label>
        <div class="layui-input-block">
            <input type="text" name="movie_Actor" lay-verify="required" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认修改</button>
        </div>
    </div>
</div>
</div>
<script src="../../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="../../../lib/jquery-3.4.1/jquery-3.4.1.min.js"></script>

<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;
        // console.log(window.sessionStorage.getItem("editId"));
        var editId = window.sessionStorage.getItem("moviesEditId");
        $.ajax({
            url: "/api/movies?method=DisplayMoviesById&id=" + editId,
            type: "get",
            // data: data.field,
            // dataType: "json",
            success: function (data) {
                console.log(data);

                if (data.code == 200) {
                    var info = data.data;
                    $("body > div > div:nth-child(1) > div > input").val(info.movie_Picture);
                    $("body > div > div:nth-child(2) > div > input").val(info.movie_ChineseName);
                    $("body > div > div:nth-child(3) > div > input").val(info.movie_Name);
                    $("body > div > div:nth-child(4) > div > input").val(info.movie_Age);
                    $("body > div > div:nth-child(5) > div > input").val(info.movie_Place);
                    $("body > div > div:nth-child(6) > div > input").val(info.movie_Type);
                    $("body > div > div:nth-child(7) > div > input").val(info.movie_Language);
                    $("body > div > div:nth-child(8) > div > input").val(info.movie_Subtitle);
                    $("body > div > div:nth-child(9) > div > input").val(info.movie_ReleaseDate);
                    $("body > div > div:nth-child(10) > div > input").val(info.iMDbScore);
                    $("body > div > div:nth-child(11) > div > input").val(info.dBScore);
                    $("body > div > div:nth-child(12) > div > input").val(info.movie_Times);
                    $("body > div > div:nth-child(13) > div > input").val(info.movie_Director);
                    $("body > div > div:nth-child(14) > div > input").val(info.movie_Scriptwriter);
                    $("body > div > div:nth-child(15) > div > input").val(info.movie_Actor);
                    $("body > div > div.layui-form-item.layui-form-text > div > textarea").val(info.movie_Introduction);
                    $("body > div > div:nth-child(17) > div > input").val(info.movie_Link);
                    //重新加载表单
                    form.render();
                } else if (data.code == 500) {
                    layer.msg(data.msg, function () {

                    });
                }
            }
        });

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var index = layer.alert(JSON.stringify(data.field), {
                title: '最终的提交信息'
            }, function () {
                // 关闭弹出层
                layer.close(index);
                window.sessionStorage.removeItem("editId");

                var iframeIndex = parent.layer.getFrameIndex(window.name);
                parent.layer.close(iframeIndex);

            });
            $.ajax({
                url: "/api/movies?method=UpdateMoviesById",
                type: "post",
                data: data.field,
                dataType: "json",
                success: function (data) {
                    console.log(data);
                    if (data.code == 200) {
                        layer.msg('修改成功',{time:500},function () {
                            window.location = '../movieslist.html';
                        });
                    } else if (data.code == 500) {
                        layer.msg(data.msg, function () {

                        });
                    }
                }
            });
            return false;
        });

    });
</script>
</body>
</html>